<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        .tab {
            width: 750px;
            margin: 0 auto;
        }

        .tab ul {
            display: flex;
            justify-content: center;
            align-items: center;
            /* width: 800px; */
            background-color: rgba(205, 205, 205, 0.433);
        }

        li {
            list-style: none;
            text-align: center;
            height: 45px;
            line-height: 45px;
            flex: 1;
        }

        .style {
            background-color: rgba(0, 0, 0, 0.471);
            color: #fff;
        }

        .tab_item {
            width: 750px;
            height: 400px;
            background-color: aquamarine;
        }

        .tab_item img {
            /* display: block; */
            display: none;
            width: 100%;
            height: 100%;
        }

        /* .tab .tab_item img {
           
        } */

        .tab_item  .block {
            display: block;
        }
       
    </style>
</head>

<body>
    <div class="tab">
        <div class="tab_h">
            <ul>
                <li class="style">胡歌</li>
                <li>彭于晏</li>
                <li>小乔</li>
                <li>西施</li>
                <li>李白</li>
            </ul>
        </div>
        <div class="tab_item">

            <img src="/pink/imgs/04.png" alt="" class="block">

            <img src="/pink/imgs/彭于晏.png" alt="">

            <img src="/pink/imgs/zyz_txt/1.png" alt="">

            <img src="/pink/imgs/zyz_txt/2.png" alt="">

            <img src="/pink/imgs/03.png" alt="">

        </div>
    </div>

    <script>
        let lis = document.querySelectorAll('.tab_h li')
        console.log(lis);
        for (let i = 0; i < lis.length; i++) {
            lis[i].addEventListener('mouseover', function () {
                document.querySelector('.tab_h .style').classList.remove('style')
                this.classList.add('style')

                document.querySelector('.tab_item .block').classList.remove('block')
                document.querySelector(`.tab_item  img:nth-child(${i+1})`).classList.add('block')
            })
        }
    </script>















    <!-- <script>
        var lis = document.querySelector('.tab_h').querySelectorAll('li')
        var imgs = document.querySelector('.tab_item').querySelectorAll('img')
        for (let i = 0; i < lis.length; i++) {
            lis[i].setAttribute('index', i)
            lis[i].onclick = function () {
                for (i = 0; i < lis.length; i++) {
                    lis[i].className=''
                }
                this.className = 'style'
               
                for (let i = 0; i < imgs.length; i++) {
                    imgs[i].id = ''
                }
               
                let index=this.getAttribute('index')
                //   console.log(index);
               imgs[index].id='block'

            }
        }
    </script> -->

</body>

</html>